package com.mini.core;

import com.mini.core.utils.EnumClazz.StrategyType;
import com.mini.core.utils.StrKit;

/**
 * Table save the table meta info like column name and column type.
 */
public class EntityInfo {
	
	private String name;
	private StrategyType strategy;
	private String[] ignore_field;
	private String[] ignore_insert_field;
	private String[] ignore_update_field;
	private String[] not_null_field;
	private String[] primaryKey = null;
	private Class<? extends BaseEntity> modelClass;
	
	public EntityInfo(String name, Class<? extends BaseEntity> modelClass) {
		if (StrKit.isBlank(name))
			throw new IllegalArgumentException("Table name can not be blank.");
		if (modelClass == null)
			throw new IllegalArgumentException("Model class can not be null.");
		
		this.name = name.trim();
		this.modelClass = modelClass;
	}
	
	public EntityInfo(String name, String[] primaryKey, Class<? extends BaseEntity> modelClass) {
		if (StrKit.isBlank(name))
			throw new IllegalArgumentException("Table name can not be blank.");
		if (primaryKey==null||primaryKey.length==0)
			throw new IllegalArgumentException("Primary key can not be blank.");
		if (modelClass == null)
			throw new IllegalArgumentException("Model class can not be null.");
		
		this.name = name.trim();
		this.primaryKey = primaryKey;
		this.modelClass = modelClass;
	}
	
	public EntityInfo(String name,
			String[] primaryKey,
			StrategyType strategy,
			String[] ignore_field,
			String[] ignore_insert_field,
			String[] ignore_update_field,
			String[] not_null_field,
			Class<? extends BaseEntity> modelClass) {
		if (StrKit.isBlank(name))
			throw new IllegalArgumentException("Table name can not be blank.");
		if (primaryKey==null||primaryKey.length==0)
			throw new IllegalArgumentException("Primary key can not be blank.");
		if (modelClass == null)
			throw new IllegalArgumentException("Model class can not be null.");
		
		this.name = name.trim();
		this.primaryKey = primaryKey;
		this.modelClass = modelClass;
		
		this.strategy = strategy;
		this.ignore_field = ignore_field;
		this.ignore_insert_field = ignore_insert_field;
		this.ignore_update_field = ignore_update_field;
		this.not_null_field = not_null_field;
	}
	
	public String getName() {
		return name;
	}
	
	/**
	 * update() and delete() need this method.
	 */
	public String[] getPrimaryKey() {
		return primaryKey;
	}
	
	public StrategyType getStrategy() {
		return strategy;
	}

	public void setStrategy(StrategyType strategy) {
		this.strategy = strategy;
	}

	public Class<? extends BaseEntity> getModelClass() {
		return modelClass;
	}

	public String[] getIgnore_field() {
		return ignore_field;
	}

	public void setIgnore_field(String[] ignore_field) {
		this.ignore_field = ignore_field;
	}

	public String[] getIgnore_insert_field() {
		return ignore_insert_field;
	}

	public void setIgnore_insert_field(String[] ignore_insert_field) {
		this.ignore_insert_field = ignore_insert_field;
	}

	public String[] getIgnore_update_field() {
		return ignore_update_field;
	}

	public void setIgnore_update_field(String[] ignore_update_field) {
		this.ignore_update_field = ignore_update_field;
	}

	public String[] getNot_null_field() {
		return not_null_field;
	}

	public void setNot_null_field(String[] not_null_field) {
		this.not_null_field = not_null_field;
	}
	
	
}





